package gugga.tasks
{
	import flash.events.EventDispatcher;
	
	import gugga.tasks.events.ProgressiveTaskEvent;
	import gugga.tasks.events.TaskEvent;

	[Event(name="start", type="TaskEvent")]
	[Event(name="interrupted", type="TaskEvent")]
	[Event(name="completed", type="TaskEvent")]

	/**
 	 * <code>FictiveTask</code> is a task that immediately after its 
 	 * <code>start()</code> fires the <b><i>start</i></b>, <b><i>progress</i></b> 
	 * and <b><i>completed</i></b> events. 
	 */
	public class FictiveTask extends EventDispatcher implements IProgressiveTask
	{
		private var mIsRunning:Boolean = false;
		private var mProgress:Number = 0;
		
		public function start() : void
		{
			mIsRunning = true;
			mProgress = 0;
			dispatchEvent(new TaskEvent(TaskEvent.START));
			dispatchEvent(new ProgressiveTaskEvent(ProgressiveTaskEvent.PROGRESS, 100, 100, 100));
			mProgress = 100;
			mIsRunning = false;
			dispatchEvent(new TaskEvent(TaskEvent.COMPLETED));
		}
		
		public function isImmediatelyInterruptable() : Boolean
		{
			return true;
		}
		
		public function interrupt() : void
		{
			mIsRunning = false;
			dispatchEvent(new TaskEvent(TaskEvent.INTERRUPTED));
		}
		
		public function getProgress() : Number 
		{
			return mProgress;
		}
	
		public function isRunning() : Boolean
		{
			return mIsRunning;
		}
	}
}